# 完整转换脚本
import re

# 读取文件
file_path = r'd:\workspace\idea\gitee\cms\gitee\spring-boot-cmstab-qiye\src\main\java\com\cms\jy\draft\constant\video_effect_meta.py'

with open(file_path, 'r', encoding='utf-8') as f:
    content = f.read()

# 分割文件内容为行
lines = content.split('\n')

# 存储解析的效果
effects = []

# 当前正在解析的效果
current_effect = None

print("开始解析效果...")

# 遍历每一行
i = 0
while i < len(lines):
    line = lines[i]
    
    # 查找效果定义行
    if '=' in line and 'Effect_meta(' in line and not '"""' in line:
        # 提取变量名
        var_match = re.search(r'(\w+)\s*=', line)
        if var_match:
            var_name = var_match.group(1)
            
            # 提取Effect_meta参数
            effect_match = re.search(r'Effect_meta\("([^"]+)",\s*(True|False),\s*"([^"]+)",\s*"([^"]+)",\s*"([^"]+)"', line)
            if effect_match:
                name = effect_match.group(1)
                is_vip = effect_match.group(2)
                resource_id = effect_match.group(3)
                effect_id = effect_match.group(4)
                md5 = effect_match.group(5)
                
                # 创建效果对象
                current_effect = {
                    'var_name': var_name,
                    'name': name,
                    'is_vip': is_vip,
                    'resource_id': resource_id,
                    'effect_id': effect_id,
                    'md5': md5,
                    'params': []
                }
                
                # 查找参数（可能在多行中）
                params_content = line
                bracket_count = line.count('[') - line.count(']')
                
                # 如果括号没有闭合，继续读取下一行直到闭合
                while bracket_count > 0 and i + 1 < len(lines):
                    i += 1
                    next_line = lines[i]
                    params_content += next_line
                    bracket_count += next_line.count('[') - next_line.count(']')
                
                # 解析参数
                param_matches = re.findall(r'Effect_param\("([^"]+)",\s*([0-9.]+),\s*([0-9.]+),\s*([0-9.]+)\)', params_content)
                for param_match in param_matches:
                    param_name = param_match[0]
                    value = param_match[1]
                    min_val = param_match[2]
                    max_val = param_match[3]
                    
                    current_effect['params'].append({
                        'name': param_name,
                        'value': value,
                        'min_val': min_val,
                        'max_val': max_val
                    })
                
                effects.append(current_effect)
                # 显示进度
                if len(effects) % 100 == 0:
                    print(f"已解析 {len(effects)} 个效果...")
    
    i += 1

print(f"解析完成，共找到 {len(effects)} 个效果。")

# 转换为Java代码
def to_pinyin_var(var_name):
    """将中文变量名转换为拼音加下划线格式"""
    # 中文到拼音的映射（包含我们需要的）
    chinese_to_pinyin = {
        '画质': 'HUA_ZHI',
        '录制框': 'LU_ZHI_KUANG',
        '界面': 'JIE_MIAN',
        '边框': 'BIAN_KUANG',
        '描边': 'MIAO_BIAN',
        '信号': 'SIGNAL',
        '开幕': 'KAI_MU',
        '钻石': 'ZHUAN_SHI',
        '放大镜': 'FANG_DA_JING',
        '灯光': 'DENG_GUANG',
        '弹窗关闭': 'DAN_CHUANG_GUAN_BI',
        '弹窗打开': 'DAN_CHUANG_DA_KAI',
        '丁达尔光线': 'DING_DA_ER_GUANG_XIAN',
        '万圣': 'WAN_SHENG',
        'emoji': 'EMOJI',
        '夜': 'YE',
        '三': 'SAN',
        '屏': 'PING',
        '格漫画': 'GE_MAN_HUA',
        '下雨': 'XIA_YU',
        '不对劲': 'BU_DUI_JIN',
        '不规则': 'BU_GUI_ZE',
        '黑框': 'HEI_KUANG',
        '两': 'LIANG',
        '中枪了': 'ZHONG_QIANG_LE',
        '乌鸦飞过': 'WU_YA_FEI_GUO',
        '九': 'JIU',
        '跑马灯': 'PAO_MA_DENG',
        '亮片': 'LIANG_PIAN',
        '人鱼': 'REN_YU',
        '滤镜': 'LV_JING',
        '仙女': 'XIAN_NU',
        '变身': 'BIAN_SHEN',
        '棒': 'BANG',
        '仙尘闪闪': 'XIAN_CHEN_SHAN_SHAN',
        '低': 'DI',
        '像素': 'XIANG_SU',
        '倒计时': 'DAO_JI_SHI',
        '像素画': 'XIANG_SU_HUA',
        '圣诞': 'SHENG_DAN',
        '光斑': 'GUANG_BAN',
        '彩光': 'CAI_GUANG',
        '摇晃': 'YAO_HUANG',
        '频闪': 'PIN_SHAN',
        '彩虹': 'CAI_HONG',
        '泛光': 'FAN_GUANG',
        '闪屏': 'SHAN_PING',
        '全息': 'QUAN_XI',
        '扫描': 'SAO_MIAO',
        '电光': 'DIAN_GUANG',
        '爆闪': 'BAO_SHAN',
        '爱心': 'AI_XIN',
        '灼烧': 'ZHUO_SHAO',
        '眼': 'YAN',
        '波动': 'BO_DONG',
        '迷幻': 'MI_HUAN',
        '震动': 'ZHEN_DONG',
        '欧根纱': 'OU_GEN_SHA',
        '卡通': 'KA_TONG',
        '渲染': 'XUAN_RAN',
        '发光': 'FA_GUANG',
        'HDR': 'HDR',
        '梦境': 'MENG_JING',
        '赛博': 'SAI_BO',
        '眼镜': 'YAN_JING',
        '轻金属': 'QING_JIN_SHU',
        '运动轨迹': 'YUN_DONG_GUI_JI',
        '脉搏': 'MAI_BO',
        '跳动': 'TIAO_DONG',
        '色差': 'SE_CHA',
        '震闪': 'ZHEN_SHAN',
        '交叉': 'JIAO_CHA',
        '居中': 'JU_ZHONG',
        '闪切': 'SHAN_QIE',
        '屏幕': 'PING_MU',
        '律动': 'LV_DONG',
        '取景器': 'QU_JING_QI',
        '放映机': 'FANG_YING_JI',
        '卡顿': 'KA_DUN',
        '磁带': 'CI_DAI',
        '碎闪': 'SUI_SHAN',
        '实况': 'SHI_KUANG',
        'S形': 'S_XING',
        '运镜': 'YUN_JING',
        '百叶窗': 'BAI_YE_CHUANG',
        '监控': 'JIAN_KONG',
        '相机': 'XIANG_JI',
        '相纸': 'XIANG_ZHI',
        '瞬间': 'SHUN_JIAN',
        '模糊': 'MO_HU',
        'VHS': 'VHS',
        '故障': 'GU_ZHANG',
        '抖动': 'DOU_DONG',
        '雪花': 'XUE_HUA',
        '噪点': 'ZAO_DIAN',
        '胶片': 'JIAO_PIAN',
        '显影': 'XIAN_YING',
        '强锐化': 'QIANG_RUI_HUA',
        '录像带': 'LU_XIANG_DAI',
        '夕阳': 'XI_YANG',
        '夜蝶': 'YE_DIE',
        '夜视': 'YE_SHI',
        '大雪': 'DA_XUE',
        '相纸': 'XIANG_ZHI',
        '瞬间模糊': 'SHUN_JIAN_MO_HU',
        '光斑虚化': 'GUANG_BAN_XU_HUA',
        '光斑飘落': 'GUANG_BAN_PIAO_LUO',
        '光晕': 'GUANG_YUN',
        '全剧终': 'QUAN_JU_ZHONG',
        '关月亮': 'GUAN_YUE_LIANG',
        '冰冷实验室': 'BING_LENG_SHI_YAN_SHI',
        '冰霜': 'BING_SHUANG',
        '冲击波': 'CHONG_JI_BO',
        '冲刺': 'CHONG_CI',
        '冲屏闪粉': 'CHONG_PING_SHAN_FEN',
        '粒子': 'LI_ZI',
        '下雨': 'XIA_YU',
        '飘雪': 'PIAO_XUE',
        '樱花': 'YING_HUA',
        '蒲公英': 'PU_GONG_YING',
        '枫叶': 'FENG_YE',
        '玫瑰花': 'MEI_GUI_HUA',
        '爱心雨': 'AI_XIN_YU',
        '星碎': 'XING_SUI',
        '星环': 'XING_HUAN',
        '流星': 'LIU_XING',
        '极光': 'JI_GUANG',
        '银河': 'YIN_HE',
        '黑洞': 'HEI_DONG',
        '水波纹': 'SHUI_BO_WEN',
        '涟漪': 'LIAN_YI',
        '气泡': 'QI_PAO',
        '蒸汽': 'ZHENG_QI',
        '烟雾': 'YAN_WU',
        '云朵': 'YUN_DUO',
        '龙卷风': 'LONG_JUAN_FENG',
        '龙息': 'LONG_XI',
        '火球': 'HUO_QIU',
        '岩浆': 'YAN_JIANG',
        '闪电': 'SHAN_DIAN',
        '雷电': 'LEI_DIAN',
        '电流': 'DIAN_LIU',
        '霓虹': 'NI_HONG',
        '光线': 'GUANG_XIAN',
        '激光': 'JI_GUANG',
        '光纤': 'GUANG_XIAN',
        '全息光': 'QUAN_XI_GUANG',
        '彩虹光': 'CAI_HONG_GUANG',
        '极光球': 'JI_GUANG_QIU',
        '光剑': 'GUANG_JIAN',
        '光刃': 'GUANG_REN',
        '光球': 'GUANG_QIU',
        '光束': 'GUANG_SHU',
        '光墙': 'GUANG_QIANG',
        '光柱': 'GUANG_ZHU',
        '光幕': 'GUANG_MU',
        '光轮': 'GUANG_LUN',
        '光环': 'GUANG_HUAN',
        '光圈': 'GUANG_QUAN',
        '光点': 'GUANG_DIAN',
        '光斑': 'GUANG_BAN',
        '光晕': 'GUANG_YUN',
        '光效': 'GUANG_XIAO',
        '光': 'GUANG'
    }
    
    # 如果变量名已经是英文或以下划线开头的英文，则直接返回
    if re.match(r'^[a-zA-Z_][a-zA-Z0-9_]*$', var_name) and not re.search(r'[\u4e00-\u9fff]', var_name):
        # 如果是以下划线开头，保持原样
        if var_name.startswith('_'):
            return var_name.upper()
        # 其他英文变量名转为大写
        return var_name.upper()
    
    # 处理包含中文的变量名
    result = var_name
    for chinese, pinyin in chinese_to_pinyin.items():
        result = result.replace(chinese, pinyin)
    
    # 处理空格和特殊字符
    result = result.replace(' ', '_')
    result = result.replace('-', '_')
    result = result.replace('(', '_')
    result = result.replace(')', '')
    result = result.replace('__', '_')
    
    # 转为大写
    result = result.upper()
    
    # 确保不以下划线开头（除非原来是以下划线开头的）
    if not var_name.startswith('_') and result.startswith('_'):
        result = result[1:]
    
    return result

# 生成Java代码
java_code = []

print("开始生成Java代码...")

for effect in effects:
    var_name = to_pinyin_var(effect['var_name'])
    name = effect['name']
    is_vip = effect['is_vip'].lower()
    resource_id = effect['resource_id']
    effect_id = effect['effect_id']
    md5 = effect['md5']
    
    if not effect['params']:  # 没有参数
        java_line = f'        public static final Effect {var_name} = new Effect("{name}", {is_vip}, "{resource_id}", "{effect_id}", "{md5}");'
    else:  # 有参数
        params_lines = []
        for param in effect['params']:
            param_line = f'                new EffectParam("{param["name"]}", {float(param["value"])}, {float(param["min_val"])}, {float(param["max_val"])})'
            params_lines.append(param_line)
        
        params_str = ',\n'.join(params_lines)
        java_line = f'        public static final Effect {var_name} = new Effect("{name}", {is_vip}, "{resource_id}", "{effect_id}", "{md5}",\n{params_str});'
    
    java_code.append(java_line)

print("Java代码生成完成。")

# 写入文件
with open(r'd:\workspace\idea\gitee\cms\gitee\spring-boot-cmstab-qiye\copy\complete_converted_effects.java', 'w', encoding='utf-8') as f:
    f.write("public static class VideoSceneEffectType {\n")
    for line in java_code:
        f.write(line + '\n')
    f.write("}\n")

print(f"转换完成！共转换了 {len(effects)} 个效果，结果已保存到 complete_converted_effects.java 文件中。")